home *** CD-ROM | disk | FTP | other *** search
/ Aminet 1 (Walnut Creek) / Aminet - June 1993 [Walnut Creek].iso / usenet / sources / volume91 / utilitys / beav_132 / part01 / word.c < prev   
C/C++ Source or Header  |  1991-11-13  |  3KB  |  118 lines

  1. /*
  2. *       Word mode commands.
  3. * The routines in this file
  4. * implement commands that work unit at
  5. * a time. There are all sorts of unit mode
  6. * commands. If I do any sentence and/or paragraph
  7. * mode commands, they are likely to be put in
  8. * this file.
  9. */
  10. #include    "def.h"
  11.  
  12. extern  BUFFER    sav_buf;
  13. char    forwunit ();
  14.  
  15. /*
  16. * Move the cursor backward by
  17. * "n" units. All of the details of motion
  18. * are performed by the "backchar" and "forwchar"
  19. * routines. Error if you try to move beyond
  20. * the buffers.
  21. */
  22. char    backunit (f, n, k)
  23. {
  24.     char    ret;
  25.  
  26.     if (n < 0)
  27.         return (forwunit (f, -n, KRANDOM));
  28.  
  29.     curwp -> w_unit_offset = 0;
  30.     while (n--)
  31.     {
  32.         ret = move_ptr (curwp, -(long)R_B_PER_U(curwp), TRUE, TRUE, TRUE);
  33.     }
  34.     wind_on_dot (curwp);
  35.     curwp -> w_flag |= WFMODE;  /* update mode line */
  36.     return (ret);
  37. }
  38.  
  39.  
  40. /*
  41. * Move the cursor forward by
  42. * the specified number of units. All of the
  43. * motion is done by "forwchar". Error if you
  44. * try and move beyond the buffer's end.
  45. */
  46. char    forwunit (f, n, k)
  47. {
  48.  
  49.     if      (n < 0)
  50.         return (backunit (f, -n, KRANDOM));
  51.  
  52.     curwp -> w_unit_offset = 0;
  53.     while (n--)
  54.     {
  55.         move_ptr (curwp, (long)R_B_PER_U(curwp), TRUE, TRUE, TRUE);
  56.     }
  57.     wind_on_dot (curwp);
  58.     curwp -> w_flag |= WFMODE;  /* update mode line */
  59.     return (TRUE);
  60. }
  61.  
  62.  
  63. /*
  64. * Kill forward by "n" units. The rules for final
  65. * status are now different. It is not considered an error
  66. * to delete fewer units than you asked. This lets you say
  67. * "kill lots of units" and have the command stop in a reasonable
  68. * way when it hits the end of the buffer.
  69. */
  70. bool delfunit (f, n, k)
  71. {
  72.     if (n < 0)
  73.         return (FALSE);
  74.     if ((lastflag & CFKILL) == 0)/* Purge kill buffer.   */
  75.         bclear (&sav_buf);
  76.     thisflag |= CFKILL;
  77.     while (n--)
  78.     {
  79.         ldelete ((A32)(R_B_PER_U(curwp)), TRUE);
  80.     }
  81.     curwp -> w_flag |= WFHARD;
  82.     curwp -> w_unit_offset = 0;
  83.     return (TRUE);
  84. }
  85.  
  86.  
  87. /*
  88. * Kill backwards by "n" units. The rules
  89. * for success and failure are now different, to prevent
  90. * strange behavior at the start of the buffer. The command
  91. * only fails if something goes wrong with the actual delete
  92. * of the characters. It is successful even if no characters
  93. * are deleted, or if you say delete 5 units, and there are
  94. * only 4 units left. I considered making the first call
  95. * to "backchar" special, but decided that that would just
  96. * be wierd. Normally this is bound to "M-Rubout" and
  97. * to "M-Backspace".
  98. */
  99. bool delbunit (f, n, k)
  100. {
  101.     int size;
  102.  
  103.     if (n < 0)
  104.         return (FALSE);
  105.     if ((lastflag & CFKILL) == 0)/* Purge kill buffer.   */
  106.         bclear (&sav_buf);
  107.     thisflag |= CFKILL;
  108.     size = R_B_PER_U(curwp);
  109.     while (n--)
  110.     {
  111.         if (move_ptr (curwp, -((long)size), TRUE, TRUE, TRUE))
  112.             ldelete ((A32)size, TRUE);
  113.     }
  114.     curwp -> w_flag |= WFHARD;
  115.     return (TRUE);
  116. }
  117.  
  118.